<template>
  <a-modal
    title="表字段信息"
    :visible="visible"
    ok-text="保存"
    @ok="handleSubmit"
    @cancel="handleCancel"
    :destroyOnClose="true"
  >
    <a-form-model ref="form" :model="queryParam" :rules="validatorRules">
      <a-form-model-item label="字段英文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="version">
        <a-input v-model="queryParam.fieldName" disabled></a-input>
      </a-form-model-item>
      <a-form-model-item label="字段中文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="notes">
        <a-input v-model="queryParam.fieldAnnotation"></a-input>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import moment from 'moment'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
export default {
  name: 'UserModal',
  components: {},
  props: ['modelId'],
  data() {
    return {
      queryParam: {},
      yearPickShow: false,
      visible: false,
      validatorRules: {
        // flag: [{ required: true, message: '请选择审批结果' }],
        // opinion: [{ required: true, message: '请输入说明' }],
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      approvalList: [
        {
          label: '上报',
          value: 1,
        },
        {
          label: '通过并上报',
          value: 2,
        },
        {
          label: '通过',
          value: 3,
        },
        {
          label: '驳回',
          value: 4,
        },
      ],
      rowData: {},
      url: {
        add: '/metaDataCollect/updateCollectField',
      },
    }
  },
  created() {},
  methods: {
    edit(record) {
      this.queryParam = Object.assign({}, record)
    },
    handleSubmit() {
      // postAction(this.url.add, params).then((res) => {
      //   if (res.success) {
      //     this.$message.success(res.message)
      //     this.visible = false
      //   } else {
      //     this.$message.error(res.message)
      //   }
      // })
      // this.queryParam = {}
      this.$refs.form.validate((valid) => {
        if (valid) {
          postAction(
            `${this.url.add}?fieldId=${this.queryParam.id}&annotation=${this.queryParam.fieldAnnotation}`
          ).then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.visible = false
              this.queryParam = {}
              this.$emit('submited')
            } else {
              this.$message.error(res.message)
            }
          })
        }
      })
    },
    handleCancel(e) {
      this.queryParam = {
        year: '',
      }
      this.visible = false
    },
    moment,
    // 得到年份选择器的值
    handlePanelChange(value) {
      this.queryParam.year = moment(value).format('YYYY')
      this.yearPickShow = false
      this.$refs.form.validateField('year', (error) => {
        console.log(error)
      })
    },
    // 弹出日历和关闭日历的回调
    handleOpenChange(status) {
      this.yearPickShow = status
    },
  },
}
</script>

<style scoped>
</style>
